home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Networking / OT PAPServerSample / EnableEOMSample.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-28  |  3.0 KB  |  96 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        EnableEOMSample.c
  3.  
  4.     Contains:    Demonstrate the use of the OTOptionManagement call to tell a PAP or
  5.                 ADSP endpoint to enable/disable the EOM option.
  6.             
  7.                 Note that this sample does not support asynch endpoints.  To support
  8.                 an asynch endpoint, the same call to OTOptionManagement would happen
  9.                 however, the endpoint handler will be called with the
  10.                 T_OPTMGMTCOMPLETE event.  The handler would then inspect the cookie, 
  11.                 which will be the TOptMgmt "ret" value to check for the
  12.                 success or failure of the call.
  13.  
  14.     Written by: Rich Kubota    
  15.  
  16.     Copyright:    Copyright © 1999 by Apple Computer, Inc., All Rights Reserved.
  17.  
  18.                 You may incorporate this Apple sample source code into your program(s) without
  19.                 restriction. This Apple sample source code has been provided "AS IS" and the
  20.                 responsibility for its operation is yours. You are not permitted to redistribute
  21.                 this Apple sample source code as "Apple sample source code" after having made
  22.                 changes. If you're going to re-distribute the source, we require that you make
  23.                 it clear in the source that the code was descended from Apple sample source
  24.                 code, but that you've made changes.
  25.  
  26.     Change History (most recent first):
  27.                 7/22/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  28.                 
  29.  
  30. */
  31.  
  32. #include "OpenTransport.h"            // open transport files            
  33. #include "OpenTptAppletalk.h"
  34.  
  35. extern OSStatus DoNegotiateEOMOption(EndpointRef ep, Boolean enableEOM);
  36.  
  37. /*
  38.     Sample function to enable/disable the EOM option for 
  39.     ADSP.  This function also demonstrates the
  40.     use of the OTOptionManagement call.
  41.     
  42.     Unless explicitely defined by XTI, all Open Transport options
  43.     use a kOTFourByteOptionSize buffer.
  44.     
  45.     Input
  46.     EndpointRef ep - endpoint on which to set EOM option on
  47.     Boolean enableEOM - true - option on, false - option off
  48.  
  49.    Return: kOTNoError indicates that the option was successfully negotiated
  50.                OSStatus is an error if < 0, otherwise, the status field is
  51.                returned and is > 0.
  52.     
  53. */
  54. OSStatus DoNegotiateEOMOption(EndpointRef ep, Boolean enableEOM)
  55.  
  56. {
  57.     UInt8        buf[kOTFourByteOptionSize];    // define buffer for fourByte Option size
  58.     TOption*    opt;                        // option ptr to make items easier to access
  59.     TOptMgmt    req;
  60.     TOptMgmt    ret;
  61.     OSStatus    err;
  62.     
  63.     if (OTIsSynchronous(ep) == false)            // check whether ep sync or not
  64.     {
  65.         DebugStr("\pThis routine does not support asynch endpoints");
  66.         return (OSStatus)-1;
  67.     }
  68.                 
  69.     opt = (TOption*)buf;                    // set option ptr to buffer
  70.     req.opt.buf    = buf;
  71.     req.opt.len    = sizeof(buf);
  72.     req.flags    = T_NEGOTIATE;                // negotiate for EOM option
  73.  
  74.     ret.opt.buf = buf;
  75.     ret.opt.maxlen = kOTFourByteOptionSize;
  76.     
  77.     opt->level    = ATK_PAP;                    // dealing with PAP
  78.     opt->name    = OPT_ENABLEEOM;
  79.     opt->len    = kOTFourByteOptionSize;
  80.     opt->status = 0;
  81.     *(UInt32*)opt->value = enableEOM;        // set the desired option level, true or false
  82.  
  83.     err = OTOptionManagement(ep, &req, &ret);
  84.     
  85.         // if no error then return the option status value
  86.     if (err == kOTNoError)
  87.     {
  88.         if (opt->status != T_SUCCESS)
  89.             err = opt->status;
  90.         else
  91.             err = kOTNoError;
  92.     }
  93.         
  94.     return err;
  95. }
  96.